<template>

  <div class="flex-center">
    <div class="box" style="width: 800px;height:1000px;border: 1px solid silver">
      <el-card style="width: 800px;height:1000px;" class="form-container" shadow="never">
        <el-form :model="brand" ref="brandFrom" label-width="150px">
          <el-form-item label="品牌名称：" prop="name">
            <el-input v-model="brand.name"></el-input>
          </el-form-item>
          <el-form-item label="品牌首字母：">
            <el-input v-model="brand.firstLetter"></el-input>
          </el-form-item>
          <el-form-item label="品牌LOGO：" prop="logo">
<!--            <Upload  v-model="brand.logo"></Upload>-->
            <image-upload v-model="brand.logo"></image-upload>
          </el-form-item>
          <el-form-item label="品牌专区大图：">
<!--            <Upload  v-model="brand.bigPic"></Upload>-->
            <image-upload v-model="brand.bigPic"></image-upload>
          </el-form-item>
          <el-form-item label="品牌故事：">
            <el-input
              placeholder="请输入内容"
              type="textarea"
              v-model="brand.brandStory"
              :autosize="true"></el-input>
          </el-form-item>
          <el-form-item label="排序：" prop="sort">
            <el-input v-model.number="brand.sort"></el-input>
          </el-form-item>
          <el-form-item label="是否显示：">
            <el-radio-group v-model="brand.showStatus">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="品牌制造商：">
            <el-radio-group v-model="brand.factoryStatus">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit('brandFrom')">提交</el-button>
            <el-button v-if="!isEdit" @click="resetForm('brandFrom')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {resetForm} from "@/utils/ruoyi";
import Upload from '@/components/FileUpload/index.vue'
import {findBrandById, updateBrand} from "@/api/product/brand";

const defaultBrand = {
  bigPic: '',
  brandStory: '',
  factoryStatus: 0,
  firstLetter: '',
  logo: '',
  name: '',
  showStatus: 0,
  sort: 0
};
export default {
  //import引入的组件需要注入到对象中才能使用"

  components: {Upload},
  props: {
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    //这里存放数据"
    return {
      brand: Object.assign({}, defaultBrand),
      id: this.$route.query.id,
    };
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    onSubmit() {
      updateBrand(this.brand).then(res=>{
        console.log(res)
        this.$message({
          type: 'success',
          message: '修改成功'
        });
        this.$router.back();
      })
    },
    findById(){
      findBrandById(this.$route.query.id).then(res=>{
        this.brand = res.data;
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.brand = Object.assign({},defaultBrand);
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.findById();
    if (this.isEdit) {
      getBrand(this.$route.query.id).then(response => {
        this.brand = response.data;
      });
    } else {
      this.brand = Object.assign({}, defaultBrand);
    }
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {


  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style scoped>
.flex-center {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  height: 80vh; /* 假设你想要盒子在视口中垂直居中 */
}

.box {
  /* 你的盒子样式 */
}
</style>
